package com.superm.controller;

import com.superm.entity.MemberLeve;
import com.superm.service.impl.MemberLeveServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/memberLeve")
public class MemberLeveController {

    @Autowired
    private MemberLeveServiceImpl memberLeveService;


    /**
     * 跳转到供应商管理页面
     * @return
     */
    @RequestMapping("/memberLeves")
    public ModelAndView memberLeves(){
        ModelAndView mv = new ModelAndView("memberLeve/MemberLeveList");
        return mv;
    }

    /**
     * 模糊查询供应商信息
     * @return
     */
    @RequestMapping("/selectMemberLeve")
    @ResponseBody  //返回真实数据
    public Map<String,Object> selectMemberLeve(MemberLeve memberLeve, @RequestParam("page") Integer pageNo, @RequestParam("limit")Integer pageSize){
        Map<String,Object> map = new HashMap<String,Object>();
        List<MemberLeve> MemberLeveList =  memberLeveService.selectLikeMemberLeveList(memberLeve,pageNo,pageSize);
        //获取总条数
        Integer count = memberLeveService.selectMemberLeveCount(memberLeve);
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",MemberLeveList);
        return map;
    }

    /**
     * 跳转到供应商添加页面
     * @return
     */
    @RequestMapping("/addMemberLeves")
    public ModelAndView addMemberLeves(MemberLeve memberLeve){
        ModelAndView mv = new ModelAndView("memberLeve/addMemberLeve");
        return mv;
    }

    /**
     * 供应商信息添加
     * @return
     */
    @RequestMapping("/addMemberLeve")
    @ResponseBody
    public Map<String,Object> addMemberLeve(MemberLeve memberLeve){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);

        if (memberLeveService.addMemberLeve(memberLeve)>0){
            map.put("success",true);
            map.put("msg","添加成功");
        }else {
            map.put("success",false);
            map.put("msg","添加失败");
        }
        return map;
    }


    /**
     * 跳转到用户修改页面
     * @return
     */
    @RequestMapping("/updateMemberLeves")
    public ModelAndView updateMemberLeves(Integer memberLeveId){
        ModelAndView mv = new ModelAndView();
        MemberLeve memberLeve1 =   memberLeveService.selectIdMem(memberLeveId);
        mv.addObject("memberLeve",memberLeve1);
        mv.setViewName("memberLeve/updateMemberLeve");
        return mv;
    }

    /**
     * 供应商信息修改
     * @return
     */
    @RequestMapping("/updateMemberLeve")
    @ResponseBody
    public Map<String,Object> updateMemberLeve(MemberLeve memberLeve){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);

        if (memberLeveService.updateMemberLeve(memberLeve)>0){
            map.put("success",true);
            map.put("msg","修改成功");
        }else {
            map.put("success",false);
            map.put("msg","修改失败");
        }
        return map;
    }

    /**
     * 删除用户信息
     * @param memberLeveId
     * @return
     */
    @RequestMapping("/deleteMemberLeve")
    @ResponseBody
    public Map<String,Object>deleteMemberLeve(@RequestParam("memberLeveId")Integer memberLeveId){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code",0);
        if (memberLeveService.deleteMemberLeve(memberLeveId)>0){
            map.put("success",true);
            map.put("msg","删除成功");
        }else{
            map.put("success",false);
            map.put("msg","删除失败");
        }
        return  map;
    }

}
